package com.xiaoyu.izf.service;

import cn.hutool.core.convert.Convert;
import com.google.common.collect.Lists;
import com.xiaoyu.izf.model.MerchantShopInfo;
import com.xiaoyu.izf.model.page.DataTableBean;
import com.xiaoyu.izf.model.page.ParamListBean;
import com.xiaoyu.izf.repository.MerchantShopInfoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;

@Service
public class MerchantShopInfoService extends BaseService {

    @Autowired
    private MerchantShopInfoDao merchantShopInfoDao;

    @Transactional
    public MerchantShopInfo save(MerchantShopInfo msi){
        return merchantShopInfoDao.save(msi);
    }

    public MerchantShopInfo findByName(String name){
        return merchantShopInfoDao.findByShopName(name);
    }

    public DataTableBean shopList(ParamListBean param){
        PageRequest pageRequest = buildPageRequestSort(param.getPageNo(), param.getPageLength(), "id",param.getFieldName(),param.getCompositorType());

		Page<MerchantShopInfo> page = merchantShopInfoDao.findByMerchantId(Convert.toInt(param.getParam().get("merchantId")),pageRequest);

        return dataTableBean(page,param);
    }
}
